package com.bt.lms.ui.page.teaching.arrange;

import com.bt.lms.ui.action.teaching.arrange.FinishArrangeBtnAction;
import com.bt.lms.ui.action.teaching.arrange.NoStartTeachingArrangeBtnAction;
import com.bt.lms.ui.action.teaching.arrange.ProcessTeachingArrangeBtnAction;
import com.bt.lms.ui.vo.teaching_arrange.TeachingArrangeInfo;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 已完成的教学安排
 */
public class PageFinishTeachingArrangeList extends VBox {
    /**
     * 已完成教学那排界面长
     */
    private double preWidth = 1280;
    /**
     * 已完成的的教学安排界面高
     */
    private double preHeight = 800;

    /**
     * 列名默认长度
     */
    private double columnPreWidth = 200;

    public PageFinishTeachingArrangeList() {

        this.setPrefSize(preWidth, preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);
        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //三个按钮横向盒子
        HBox threeBtnHBox = new HBox();
        initThreeBtnHBox(threeBtnHBox);
        ///条件搜索区域横向盒子
        HBox searchHBox = new HBox();
        initSearchHBox(searchHBox);

        //结课时间盒子
        HBox finishHBox = new HBox();
        initFinishHBox(finishHBox);
        //表格盒子
        VBox tableVBox = new VBox();
        initTableVBox(tableVBox);
        //页码横向盒子
        HBox pageNumHBox = new HBox();
        initPageNumHBox(pageNumHBox);


        ObservableList<Node> children = this.getChildren();
        children.addAll(topHBox, threeBtnHBox, searchHBox, finishHBox, tableVBox, pageNumHBox);


    }




    /**
     * 页码横向盒子
     *
     * @param pageNumHBox
     */
    private void initPageNumHBox(HBox pageNumHBox) {
        pageNumHBox.setSpacing(20);
        pageNumHBox.setPadding(new Insets(10));
        pageNumHBox.setAlignment(Pos.CENTER_RIGHT);
        //首页标签
        Label homeLab = new Label("<<首页");
        homeLab.setTextFill(Color.rgb(108, 221, 83));
        homeLab.setFont(new Font(20));
        //上一页标签
        Label previousPageLab = new Label("<<上一页");
        previousPageLab.setTextFill(Color.rgb(108, 221, 83));
        previousPageLab.setFont(new Font(20));
        //第一页按钮
        Button onePageBtn = new Button("1");
        onePageBtn.setPrefWidth(27);
        onePageBtn.setPrefHeight(30);
        //第二页按钮
        Button twoPageBtn = new Button("2");
        twoPageBtn.setPrefWidth(27);
        twoPageBtn.setPrefHeight(30);
        //第三页按钮
        Button threePageBtn = new Button("3");
        threePageBtn.setPrefWidth(27);
        threePageBtn.setPrefHeight(30);
        //第四页按钮
        Button fourPageBtn = new Button("4");
        fourPageBtn.setPrefWidth(27);
        fourPageBtn.setPrefHeight(30);
        //下一页标签
        Label nextPageLab = new Label("下一页>>");
        nextPageLab.setFont(new Font(20));
        nextPageLab.setTextFill(Color.rgb(108, 221, 83));
        //尾页标签
        Label endPageLab = new Label("尾页>>");
        endPageLab.setFont(new Font(20));
        endPageLab.setTextFill(Color.rgb(108, 221, 83));
        //总记录数条
        Label totalPageLab = new Label("总页数100条");
        totalPageLab.setFont(new Font(20));
        totalPageLab.setTextFill(Color.rgb(255, 65, 55));
        //条数文本框
        TextField countTF = new TextField();
        countTF.setPrefWidth(100);
        // /10标签
        Label tenLab = new Label("/10");
        tenLab.setFont(new Font(20));
        //GO按钮
        Button goBtn = new Button("GO");
        ObservableList<Node> children = pageNumHBox.getChildren();
        children.addAll(homeLab, previousPageLab, onePageBtn, twoPageBtn, threePageBtn, fourPageBtn, nextPageLab, endPageLab, totalPageLab, countTF, tenLab, goBtn);
    }

    /**
     * 表格盒子
     *
     * @param tableVBox
     */
    private void initTableVBox(VBox tableVBox) {
        //表格
        TableView tableView = new TableView<>();

        TableColumn serialNumColumn = new TableColumn<>("序号");
        serialNumColumn.setPrefWidth(columnPreWidth);
        TableColumn courseNameColumn = new TableColumn<>("课程名称");
        courseNameColumn.setPrefWidth(columnPreWidth);
        TableColumn courseUnitColumn = new TableColumn<>("所属学习单位");
        courseUnitColumn.setPrefWidth(columnPreWidth);
        TableColumn levelColumn = new TableColumn<>("适用层次");
        levelColumn.setPrefWidth(columnPreWidth);

        TableColumn courseTeacherColumn = new TableColumn<>("授课教师");
        courseTeacherColumn.setPrefWidth(columnPreWidth);
        TableColumn startCourseTimeColumn = new TableColumn<>("开课时间");
        startCourseTimeColumn.setPrefWidth(columnPreWidth);
        TableColumn finishCourseTimeColumn = new TableColumn<>("结课时间");
        finishCourseTimeColumn.setPrefWidth(columnPreWidth);


        //课程操作列1盒子
        HBox hBox1 = new HBox();
        //查看教学监管历史数据按钮
        Button lookHistoryBtn1 = new Button("查看教学监管历史按钮");
        hBox1.getChildren().add(lookHistoryBtn1);

        //课程操作列2盒子
        HBox hBox2 = new HBox();
        //查看教学监管历史数据按钮
        Button lookHistoryBtn2 = new Button("查看教学监管历史按钮");
        hBox2.getChildren().add(lookHistoryBtn2);
        //课程操作列3盒子
        HBox hBox3 = new HBox();
        //查看教学监管历史数据按钮
        Button lookHistoryBtn3 = new Button("查看教学监管历史按钮");
        hBox3.getChildren().add(lookHistoryBtn3);


        //模拟表中数据
        TeachingArrangeInfo teachingArrangeInfo1 = new TeachingArrangeInfo("1", "教育心里学", "西南大学", "免费师范生", "学位专业课", "必修", "张老师", "2012-09-10", "2012-10-10", "50", hBox1);
        TeachingArrangeInfo teachingArrangeInfo2 = new TeachingArrangeInfo("2", "数学", "北京师范大学", "免费师范生", "基础专业课", "必修", "王老师", "2012-10-20", "2012-11-20", "50", hBox2);
        TeachingArrangeInfo teachingArrangeInfo3 = new TeachingArrangeInfo("3", "物理", "济南大学", "免费师范生", "物理课", "必修", "李老师", "2013-01-10", "2013-02-10", "50", hBox3);
        //数据集合
        List<TeachingArrangeInfo> teachingArrangeInfoList = new ArrayList<>();
        teachingArrangeInfoList.add(teachingArrangeInfo1);
        teachingArrangeInfoList.add(teachingArrangeInfo2);
        teachingArrangeInfoList.add(teachingArrangeInfo3);
        //将数据集合转换成Javafx组件集合
        ObservableList<TeachingArrangeInfo> teachingArrangeInfos = FXCollections.observableArrayList(teachingArrangeInfoList);
        tableView.setItems(teachingArrangeInfos);
        //映射到表中
        serialNumColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("serialNum"));
        courseNameColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("courseName"));
        courseUnitColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("courseUnit"));
        levelColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("level"));


        courseTeacherColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("courseTeacher"));
        startCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("startCourseTime"));
        finishCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo, String>("finishCourseTime"));


        tableVBox.getChildren().add(tableView);

        tableView.getColumns().addAll(serialNumColumn, courseNameColumn, courseUnitColumn, levelColumn, courseTeacherColumn, startCourseTimeColumn, finishCourseTimeColumn);
    }

    /**
     * 结课时间筛选盒子
     *
     * @param finishHBox
     */
    private void initFinishHBox(HBox finishHBox) {
        finishHBox.setSpacing(20);
        //按照结课时间筛选标签
        Label finishTimeLab = new Label("⏰按照结课时间筛选:");
        finishTimeLab.setTextFill(Color.rgb(238, 83, 65));
        //具体时间标签
        Label detailTimeLab = new Label("1个月内   1-3个月  3-6个月   6-12个月   1-2年   2-3年内   3-5年   5年以上 ");
        detailTimeLab.setTextFill(Color.rgb(42, 127, 194));
        finishHBox.getChildren().addAll(finishTimeLab, detailTimeLab);


    }

    /**
     * 条件搜索区域横线盒子
     *
     * @param searchHBox
     */
    private void initSearchHBox(HBox searchHBox) {
        //搜索区域横向盒子间距
        searchHBox.setSpacing(15);
        searchHBox.setPadding(new Insets(10));
        //课程单位单位标签
        Label courseUnitLab = new Label("课程开设单位");
        //课程开设单位下拉框
        ComboBox courseUnitCB = new ComboBox<>();
        courseUnitCB.getItems().add("全部");
        courseUnitCB.getItems().add("北京师范大学");
        courseUnitCB.getSelectionModel().selectFirst();

        //适用层次标签
        Label levelLab = new Label("适用层次");
        //适用层次下拉框
        ComboBox levelCB = new ComboBox<>();
        levelCB.getItems().add("全部");
        levelCB.getItems().add("免费师范生");
        levelCB.getItems().add("免费师范生教育硕士");
        levelCB.getItems().add("职后教育");
        levelCB.getItems().add("其他");
        levelCB.getSelectionModel().selectFirst();

        //课程编号/课程名称标签
        Label courseNum = new Label("课程编号/名称");
        ////课程编号/课程名称文本框
        TextField courseNumTF = new TextField();
        courseNumTF.setPromptText("输入课程名称");
        //搜索按钮
        Button searchBtn = new Button("搜索");


        searchHBox.getChildren().addAll(courseUnitLab, courseUnitCB, levelLab, levelCB, courseNum, courseNumTF, searchBtn);
    }

    /**
     * 三个按钮横向盒子
     *
     * @param threeBtnHBox
     */
    private void initThreeBtnHBox(HBox threeBtnHBox) {
        threeBtnHBox.setSpacing(10);
        //未实施的教学安排按钮
        Button noStartBtn = new Button("未实施的教学安排");
        BtnStyle.cancelBtn(noStartBtn);
        //未实施的教学安排按钮事件
        NoStartTeachingArrangeBtnAction noStartTeachingArrangeBtnAction = new NoStartTeachingArrangeBtnAction();
        noStartBtn.setOnAction(noStartTeachingArrangeBtnAction);
        noStartBtn.setCursor(Cursor.HAND);
        //实施中的教学安排按钮
        Button processBtn = new Button("实施中的教学安排");
        BtnStyle.cancelBtn(processBtn);
        processBtn.setCursor(Cursor.HAND);
        ProcessTeachingArrangeBtnAction processTeachingArrangeBtnAction = new ProcessTeachingArrangeBtnAction();
        processBtn.setOnAction(processTeachingArrangeBtnAction);

        //已完成的教学安排按钮
        Button finishBtn = new Button("已完成的教学安排");
        BtnStyle.cancelBtn(finishBtn);
        ObservableList<Node> children = threeBtnHBox.getChildren();
        children.addAll(noStartBtn, processBtn, finishBtn);
        //已完成的教学安排按钮事件
        FinishArrangeBtnAction finishArrangeBtnAction = new FinishArrangeBtnAction();
        finishBtn.setOnAction(finishArrangeBtnAction);
        finishBtn.setCursor(Cursor.HAND);
    }

    /**
     * 顶部横向盒子
     *
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(2));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学安排>已完成的教学安排");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }
}




